#include "debug.h"
#include "../DDIC/AllDDIC.h"


void CH13A11_Write_Gamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data);
void CH13A11_Read_Gamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data);
void CH13A11_Gamma_OTP_Start(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data);
void CH13A11_auto_Gamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data);
int GrayIndex2[34]={255,254,252,250,248,244,236,228,220,212,204,196,188,180,164,148,132,124,116,100,84,68,52,44,36,28,20,16,12,8,4,3,1,0};
u8 offIndex2[34]={0x0A,0x0A,0x05,0x05,0x05,0x05,0x00,0x00,0x00,0x00,0x0A,0x0A,0x0A,0x0A,0x05,0x05,0x05,0x05,0x00,0x00,0x00,0x00,0x0A,0x0A,0x0A,0x0A,0x05,0x05,0x05,0x05,0x00,0x00,0x00,0x00};
u8 subIndex2[34]={0x0C,0x0B,0x09,0x08,0x07,0x06,0x04,0x03,0x02,0x01,0x0E,0x0D,0x0C,0x0B,0x09,0x08,0x07,0x06,0x04,0x03,0x02,0x01,0x0E,0x0D,0x0C,0x0B,0x09,0x08,0x07,0x06,0x04,0x03,0x02,0x01};
u8 offset2[34]={2,0,6,4,2,0,6,4,2,0,6,4,2,0,6,4,2,0,6,4,2,0,6,4,2,0,6,4,2,0,6,4,2,0};
u8 reg2[34]={0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb4,0xb3,0xb3,0xb3,0xb3,0xb3,0xb3,0xb3,0xb3,0xb3,0xb3,0xb3,0xb3,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2,0xb2};


void CH13A11_Write_Gamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    u8 buffer1[7];
	  u8 CH13A11W[20];
    u8 i,j,m,k=0,temp;
	//??gamma????
	  SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data); 

		delay_ms(5);
	  buffer1[0] = 0x02;        
    buffer1[1] = 0xf0;   
		buffer1[2] = 0x52;  
    SSD2828_W_Array(SigMode,channel,buffer1,0);

	  if(buffer[3]==0x01)       //GAMMA RED
	  {
			   CH13A11W[0]= 19;
		     CH13A11W[1]= 0xB2;
				 for( i = 0;i<18;i++)   //18???
				 {	        
          CH13A11W[i+2] =  buffer[i+4];
				 }
			   SSD2828_W_Array(SigMode,channel,CH13A11W,0);
				 delay_ms(5);
				 CH13A11W[0]= 19;
		     CH13A11W[1]= 0xB3;
			 	 for( i = 0;i<18;i++)   //18???
				 {	
					 CH13A11W[i+2] =  buffer[i+22]; 
				 }
		     SSD2828_W_Array(SigMode,channel,CH13A11W,0);
				 delay_ms(5);
				 CH13A11W[0]= 16;
		     CH13A11W[1]= 0xB4;
				 for( i = 0;i<15;i++)   //15???
				 {	                                                 
					 CH13A11W[i+2] =  buffer[i+40];  
				 }
		     SSD2828_W_Array(SigMode,channel,CH13A11W,0);
				 delay_ms(5);
	  }
		else if(buffer[3]==0x02)  //GAMMA GREEN
		{
			
				 CH13A11W[0]= 19;
		     CH13A11W[1]= 0xB5;
				 for( i = 0;i<18;i++)   //18???
				 {	        
          CH13A11W[i+2] =  buffer[i+4];
				 }
			   SSD2828_W_Array(SigMode,channel,CH13A11W,0);
				 delay_ms(5);
				 CH13A11W[0]= 19;
		     CH13A11W[1]= 0xB6;
			 	 for( i = 0;i<18;i++)   //18???
				 {	
					 CH13A11W[i+2] =  buffer[i+22]; 
				 }
		     SSD2828_W_Array(SigMode,channel,CH13A11W,0);
				 delay_ms(5);
				 CH13A11W[0]= 16;
		     CH13A11W[1]= 0xB7;
				 for( i = 0;i<15;i++)   //15???
				 {	                                                 
					 CH13A11W[i+2] =  buffer[i+40];  
				 }
		     SSD2828_W_Array(SigMode,channel,CH13A11W,0);
				 delay_ms(5);
		   
		}
		else if(buffer[3]==0x03)   //GAMMA BLUE
		{
		
				CH13A11W[0]= 19;
		     CH13A11W[1]= 0xB8;
				 for( i = 0;i<18;i++)   //18???
				 {	        
          CH13A11W[i+2] =  buffer[i+4];
				 }
			   SSD2828_W_Array(SigMode,channel,CH13A11W,0);
				 delay_ms(5);
				 CH13A11W[0]= 19;
		     CH13A11W[1]= 0xB9;
			 	 for( i = 0;i<18;i++)   //18???
				 {	
					 CH13A11W[i+2] =  buffer[i+22]; 
				 }
		     SSD2828_W_Array(SigMode,channel,CH13A11W,0);
				 delay_ms(5);
				 CH13A11W[0]= 16;
		     CH13A11W[1]= 0xBA;
				 for( i = 0;i<15;i++)   //15???
				 {	                                                 
					 CH13A11W[i+2] =  buffer[i+40];  
				 }
		     SSD2828_W_Array(SigMode,channel,CH13A11W,0);
				 delay_ms(5);
		   
		} 


    buffer[4] = Uart_Error_None;
    buffer[5] = 0;
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);            //?? ??????  :ok  
	  SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
}

void CH13A11_Read_Gamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    u8 buffer1[7];
	  u8 buffer2[18];
	  u8 buffer3[18];
	  u8 buffer4[18];
    u16 tmp;
    u8 i,j,k=0;
	  SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	  buffer1[0] = 0x02;        
    buffer1[1] = 0xf0;   
		buffer1[2] = 0x52;  
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);
			if(buffer[3]==0x01)       //GAMMA RED
			{
				Generate_MIPI_Read(pdev,SigMode,channel,0xB2,18,buffer2);
				for(i=0;i<buffer[2];i++)  //data read out length
				{
						buffer[4+i]=buffer2[i];
						buffer[5+i]=buffer2[i+1];
						delay_ms(5);
						i++;
				}
				Generate_MIPI_Read(pdev,SigMode,channel,0xB3,18,buffer3);
				for(i=0;i<buffer[2];i++)  //data read out length
				{
						buffer[22+i]=buffer3[i];
						buffer[23+i]=buffer3[i+1];
						delay_ms(5);
						i++;
				}
				Generate_MIPI_Read(pdev,SigMode,channel,0xB4,18,buffer4);
				for(i=0;i<buffer[2];i++)  //data read out length
				{
						delay_ms(5);
						buffer[40+i]=buffer4[i];
						buffer[41+i]=buffer4[i+1];
						delay_ms(5);
						i++;
				}
		}
		else if (buffer[3]==0x02)  //GAMMA GREEN
		{
				Generate_MIPI_Read(pdev,SigMode,channel,0xB5,18,buffer2);
				for(i=0;i<buffer[2];i++)  //data read out length
				{
						buffer[4+i]=buffer2[i];
						buffer[5+i]=buffer2[i+1];
						delay_ms(5);
						i++;
				}
				Generate_MIPI_Read(pdev,SigMode,channel,0xB6,18,buffer3);
				for(i=0;i<buffer[2];i++)  //data read out length
				{
						buffer[22+i]=buffer3[i];
						buffer[23+i]=buffer3[i+1];
						delay_ms(5);
						i++;
				}
				Generate_MIPI_Read(pdev,SigMode,channel,0xB7,18,buffer4);
				for(i=0;i<buffer[2];i++)  //data read out length
				{
						buffer[40+i]=buffer4[i];
						buffer[41+i]=buffer4[i+1];
						delay_ms(5);
						i++;
				}
		}
		else if (buffer[3]==0x03)  //GAMMA BLUE
		{
				Generate_MIPI_Read(pdev,SigMode,channel,0xB8,18,buffer2);
				for(i=0;i<buffer[2];i++)  //data read out length
				{
						buffer[4+i]=buffer2[i];
						buffer[5+i]=buffer2[i+1];
						delay_ms(5);
						i++;
				}
				Generate_MIPI_Read(pdev,SigMode,channel,0xB9,18,buffer3);
				for(i=0;i<buffer[2];i++)  //data read out length
				{
						buffer[22+i]=buffer3[i];
						buffer[23+i]=buffer3[i+1];
						delay_ms(5);
						i++;
				}
				Generate_MIPI_Read(pdev,SigMode,channel,0xBA,18,buffer4);
				for(i=0;i<buffer[2];i++)  //data read out length
				{
						buffer[40+i]=buffer4[i];
						buffer[41+i]=buffer4[i+1];
						delay_ms(5);
						i++;
				}
		}
    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //?? ??? ?????  :ok 

}

void CH13A11_Gamma_OTP_Start(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    u16 tmp,times_flag=0;
    u8 buffer1[6];  
		if(buffer[3]==1)//otp time 1
		{	
				times_flag=0x70;
		}
		else if(buffer[3]==2)//otp time 2
		{
				times_flag=0x30;		
		}
		else if(buffer[3]==3)//otp time 2
		{
				times_flag=0x10;		
		}	
		else if(buffer[3]==4)//otp time 2
		{
				times_flag=0x00;		
		}	
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);  
    delay_ms(15);	
    buffer1[0] = 0x05;
    buffer1[1] = 0xF6;
    buffer1[2] = 0x14;
		buffer1[3] = 0x21;
		buffer1[4] = 0x00;
		buffer1[5] = 0x00;
    SSD2828_W_Array(SigMode,channel,buffer1,0);     // DSTB=1/PTM
    buffer1[0] = 0x05;
    buffer1[1] = 0xF6;
    buffer1[2] = 0x94;
		buffer1[3] = 0x21;
		buffer1[4] = 0x00;
		buffer1[5] = 0x00;
    SSD2828_W_Array(SigMode,channel,buffer1,0);     // PCE=1
	//OTP_VPP=6V ON
		delay_ms(150);
		if(buffer[4]==0x01)//otp gamma 1
		{
		//OTP RC0H INDEX=0X030C
				buffer1[0] = 0x02;
				buffer1[1] = 0xC0;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x18;
				buffer1[5] = 0x0C;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x1B;
				buffer1[5] = 0x0C;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(120);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x18;
				buffer1[5] = 0x0C;
				SSD2828_W_Array(SigMode,channel,buffer1,0);	
		}
		else if(buffer[4]==0x02) //otp demura
		{
	//OTP RBDH INDEX=0X02B8 //For Demura
				buffer1[0] = 0x02;
				buffer1[1] = 0xBD;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x10;
				buffer1[5] = 0xB8;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x13;
				buffer1[5] = 0xB8;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(10);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x10;
				buffer1[5] = 0xB8;
				SSD2828_W_Array(SigMode,channel,buffer1,0);			
		}
		else if(buffer[4]==0x00) //otp others
		{
		//OTP R6AH INDEX=0X0014
				buffer1[0] = 0x02;
				buffer1[1] = 0x6A;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x00;
				buffer1[5] = 0x14;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x03;
				buffer1[5] = 0x14;
				SSD2828_W_Array(SigMode,channel,buffer1,0);
				delay_ms(5);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x00;
				buffer1[5] = 0x14;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
//OTP RB0H INDEX=0X0033	
				buffer1[0] = 0x02;
				buffer1[1] = 0xB0;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x00;
				buffer1[5] = 0x33;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x03;
				buffer1[5] = 0x33;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(25);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x00;
				buffer1[5] = 0x33;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 
//OTP RB1H INDEX=0X0061
				buffer1[0] = 0x02;
				buffer1[1] = 0xB1;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x00;
				buffer1[5] = 0x61;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x03;
				buffer1[5] = 0x61;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(25);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x00;
				buffer1[5] = 0x61;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 				
//OTP RB2H INDEX=0X0080
				buffer1[0] = 0x02;
				buffer1[1] = 0xB2;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x00;
				buffer1[5] = 0x80;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x03;
				buffer1[5] = 0x80;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(25);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x00;
				buffer1[5] = 0x80;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 		
//OTP RB3H INDEX=0X0096
				buffer1[0] = 0x02;
				buffer1[1] = 0xB3;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x00;
				buffer1[5] = 0x96;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x03;
				buffer1[5] = 0x96;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(200);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x00;
				buffer1[5] = 0x96;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
//OTP RB4H INDEX=0X00D0
				buffer1[0] = 0x02;
				buffer1[1] = 0xB4;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x00;
				buffer1[5] = 0xD0;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x03;
				buffer1[5] = 0xD0;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(20);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x00;
				buffer1[5] = 0xD0;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 
//OTP RB5H INDEX=0X0107
				buffer1[0] = 0x02;
				buffer1[1] = 0xB5;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x08;
				buffer1[5] = 0x07;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x0B;
				buffer1[5] = 0x07;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(100);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x08;
				buffer1[5] = 0x07;
				SSD2828_W_Array(SigMode,channel,buffer1,0);				
//OTP RB9H INDEX=0X0146
				buffer1[0] = 0x02;
				buffer1[1] = 0xB9;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x08;
				buffer1[5] = 0x46;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x0B;
				buffer1[5] = 0x46;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(50);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x08;
				buffer1[5] = 0x46;
				SSD2828_W_Array(SigMode,channel,buffer1,0);		
//OTP RBAH INDEX=0X01CE
				buffer1[0] = 0x02;
				buffer1[1] = 0xBA;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x08;
				buffer1[5] = 0xCE;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x0B;
				buffer1[5] = 0xCE;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(500);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x08;
				buffer1[5] = 0xCE;
				SSD2828_W_Array(SigMode,channel,buffer1,0);			
//OTP RBBH INDEX=0X0250
				buffer1[0] = 0x02;
				buffer1[1] = 0xBB;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x10;
				buffer1[5] = 0x50;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x13;
				buffer1[5] = 0x50;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(20);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x10;
				buffer1[5] = 0x50;
				SSD2828_W_Array(SigMode,channel,buffer1,0);			
//OTP RBCH INDEX=0X0281
				buffer1[0] = 0x02;
				buffer1[1] = 0xBC;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x10;
				buffer1[5] = 0x81;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x13;
				buffer1[5] = 0x81;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(20);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x10;
				buffer1[5] = 0x81;
				SSD2828_W_Array(SigMode,channel,buffer1,0);	
//OTP RBEH INDEX=0X02BF 
				buffer1[0] = 0x02;
				buffer1[1] = 0xBE;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x10;
				buffer1[5] = 0xBF;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x13;
				buffer1[5] = 0xBF;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(10);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x10;
				buffer1[5] = 0xBF;
				SSD2828_W_Array(SigMode,channel,buffer1,0);					
//OTP RC9H INDEX=0X0E1D
				buffer1[0] = 0x02;
				buffer1[1] = 0xC9;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x70;
				buffer1[5] = 0x1D;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x73;
				buffer1[5] = 0x1D;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(140);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x70;
				buffer1[5] = 0x1D;
				SSD2828_W_Array(SigMode,channel,buffer1,0);			
//OTP RCAH INDEX=0X0F98
				buffer1[0] = 0x02;
				buffer1[1] = 0xCA;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x78;
				buffer1[5] = 0x98;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x7B;
				buffer1[5] = 0x98;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(140);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0x78;
				buffer1[5] = 0x98;
				SSD2828_W_Array(SigMode,channel,buffer1,0);		
//OTP RD0H INDEX=0X1439
				buffer1[0] = 0x02;
				buffer1[1] = 0xD0;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xA0;
				buffer1[5] = 0x39;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xA3;
				buffer1[5] = 0x39;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(20);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xA0;
				buffer1[5] = 0x39;
				SSD2828_W_Array(SigMode,channel,buffer1,0);		
//OTP RD1H INDEX=0X1467
				buffer1[0] = 0x02;
				buffer1[1] = 0xD1;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xA0;
				buffer1[5] = 0x67;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xA3;
				buffer1[5] = 0x67;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(20);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xA0;
				buffer1[5] = 0x67;
				SSD2828_W_Array(SigMode,channel,buffer1,0);					
//OTP RD2H INDEX=0X14E6
				buffer1[0] = 0x02;
				buffer1[1] = 0xD2;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xA0;
				buffer1[5] = 0xE6;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xA3;
				buffer1[5] = 0xE6;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(50);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xA0;
				buffer1[5] = 0xE6;
				SSD2828_W_Array(SigMode,channel,buffer1,0);			
//OTP RD4H INDEX=0X15E4
				buffer1[0] = 0x02;
				buffer1[1] = 0xD4;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xA8;
				buffer1[5] = 0xE4;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xAB;
				buffer1[5] = 0xE4;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(50);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xA8;
				buffer1[5] = 0xE4;
				SSD2828_W_Array(SigMode,channel,buffer1,0);				
//OTP RD7H INDEX=0X165A
				buffer1[0] = 0x02;
				buffer1[1] = 0xD7;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xB0;
				buffer1[5] = 0x5A;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xB3;
				buffer1[5] = 0x5A;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(50);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xB0;
				buffer1[5] = 0x5A;
				SSD2828_W_Array(SigMode,channel,buffer1,0);			
//OTP RD8H INDEX=0X16AF
				buffer1[0] = 0x02;
				buffer1[1] = 0xD8;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xB0;
				buffer1[5] = 0xAF;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xB3;
				buffer1[5] = 0xAF;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(10);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xB0;
				buffer1[5] = 0xAF;
				SSD2828_W_Array(SigMode,channel,buffer1,0);		
//OTP RE0H INDEX=0X19AB
				buffer1[0] = 0x02;
				buffer1[1] = 0xE0;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xC8;
				buffer1[5] = 0xAB;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xCB;
				buffer1[5] = 0xAB;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(10);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xC8;
				buffer1[5] = 0xAB;
				SSD2828_W_Array(SigMode,channel,buffer1,0);			
//OTP RE1H INDEX=0X19BB
				buffer1[0] = 0x02;
				buffer1[1] = 0xE1;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xC8;
				buffer1[5] = 0xBB;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xCB;
				buffer1[5] = 0xBB;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(30);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xC8;
				buffer1[5] = 0xBB;
				SSD2828_W_Array(SigMode,channel,buffer1,0);		
//OTP RE3H INDEX=0X1ABC
				buffer1[0] = 0x02;
				buffer1[1] = 0xE3;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xD0;
				buffer1[5] = 0xBC;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xD3;
				buffer1[5] = 0xBC;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(70);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xD0;
				buffer1[5] = 0xBC;
				SSD2828_W_Array(SigMode,channel,buffer1,0);		
//OTP RE5H INDEX=0X1B75
				buffer1[0] = 0x02;
				buffer1[1] = 0xE5;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xD8;
				buffer1[5] = 0x75;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xDB;
				buffer1[5] = 0x75;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(20);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xD8;
				buffer1[5] = 0x75;
				SSD2828_W_Array(SigMode,channel,buffer1,0);	
//OTP RE6H INDEX=0X1BA9
				buffer1[0] = 0x02;
				buffer1[1] = 0xE6;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xD8;
				buffer1[5] = 0xA9;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xDB;
				buffer1[5] = 0xA9;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(20);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xD8;
				buffer1[5] = 0xA9;
				SSD2828_W_Array(SigMode,channel,buffer1,0);	
//OTP RE7H INDEX=0X1CCA
				buffer1[0] = 0x02;
				buffer1[1] = 0xE7;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xE0;
				buffer1[5] = 0xCA;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xE3;
				buffer1[5] = 0xCA;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(40);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xE0;
				buffer1[5] = 0xCA;
				SSD2828_W_Array(SigMode,channel,buffer1,0);					
//OTP RE8H INDEX=0X1D2B
				buffer1[0] = 0x02;
				buffer1[1] = 0xE8;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xE8;
				buffer1[5] = 0x2B;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xEB;
				buffer1[5] = 0x2B;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(30);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xE8;
				buffer1[5] = 0x2B;
				SSD2828_W_Array(SigMode,channel,buffer1,0);		
//OTP REAH INDEX=0X1DA5
				buffer1[0] = 0x02;
				buffer1[1] = 0xEA;
				buffer1[2] = times_flag;
				SSD2828_W_Array(SigMode,channel,buffer1,0);  	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xE8;
				buffer1[5] = 0xA5;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 	
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xEB;
				buffer1[5] = 0xA5;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 			
				delay_ms(120);
				buffer1[0] = 0x05;
				buffer1[1] = 0xf6;
				buffer1[2] = 0x94;
				buffer1[3] = 0x21;
				buffer1[4] = 0xE8;
				buffer1[5] = 0xA5;
				SSD2828_W_Array(SigMode,channel,buffer1,0);	
			}				
//REMOVE 6V
		delay_ms(10);
		buffer1[0] = 0x05;
		buffer1[1] = 0xf6;
		buffer1[2] = 0x14;
		buffer1[3] = 0x21;
		buffer1[4] = 0x00;
		buffer1[5] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);		//PCE=0				
		buffer1[0] = 0x05;
		buffer1[1] = 0xf6;
		buffer1[2] = 0x14;
		buffer1[3] = 0x00;
		buffer1[4] = 0x00;
		buffer1[5] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);		//PTM=0/DSTB=0	
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //?? ?OTP??  :ok
}
void CH13A11_auto_Gamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	 u8 buffer1[7];
	 	SSD2828_W_Reg(SigMode,channel,0xB7,0x0019);
	//gamma????
//		buffer1[0] = 0x02;        
//    buffer1[1] = 0xf0;   
//		buffer1[2] = 0x58;  
//    SSD2828_W_Array(SigMode,channel,buffer1,0);
//	
//		buffer1[0] = 0x04;        
//    buffer1[1] = 0xc0;   
//		buffer1[2] = 0x03;  
//	  buffer1[3] = 0x6b; 
//  	buffer1[4] = 0x94; 
//    SSD2828_W_Array(SigMode,channel,buffer1,0);
//		delay_ms(5);

	
	  //SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
		buffer1[0] = 0x02;        
    buffer1[1] = 0xf0;   
		buffer1[2] = 0x52;  
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	 //r
		buffer1[0] = 0x02;        
    buffer1[1] = 0xf1;   
		buffer1[2] = offIndex2[ buffer[3]];  
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02;        
    buffer1[1] = reg2[buffer[3]];   
		buffer1[2] = buffer[4];  
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	
	
		buffer1[0] = 0x02;        
    buffer1[1] = 0xf1;   
		buffer1[2] = subIndex2[ buffer[3]];  
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02;        
    buffer1[1] = reg2[buffer[3]];   
		buffer1[2] = buffer[5];  
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		//g
		buffer1[0] = 0x02;        
    buffer1[1] = 0xf1;   
		buffer1[2] = offIndex2[ buffer[3]];  
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02;        
    buffer1[1] = reg2[buffer[3]]+3;   
		buffer1[2] = buffer[6];  
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	
		buffer1[0] = 0x02;        
    buffer1[1] = 0xf1;   
		buffer1[2] = subIndex2[ buffer[3]];  
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02;        
    buffer1[1] = reg2[buffer[3]]+3;   
		buffer1[2] = buffer[7];  
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		//b
		buffer1[0] = 0x02;        
    buffer1[1] = 0xf1;   
		buffer1[2] = offIndex2[ buffer[3]];  
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02;        
    buffer1[1] = reg2[buffer[3]]+6;   
		buffer1[2] = buffer[8];  
    SSD2828_W_Array(SigMode,channel,buffer1,0);

		buffer1[0] = 0x02;        
    buffer1[1] = 0xf1;   
		buffer1[2] = subIndex2[ buffer[3]];  
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02;        
    buffer1[1] = reg2[buffer[3]]+6;   
		buffer1[2] = buffer[9];  
    SSD2828_W_Array(SigMode,channel,buffer1,0);
}


void ProcessForIc81( USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8 buffer[],u16 LP_B7_Data,u16 HS_B7_Data)//ADD BY PCS
{
	switch(buffer[1]&0xFF)
	{
		case 0x08:                                      //?Gamma
			CH13A11_Write_Gamma(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);
		break;
		case 0x09:                                      //?Gamma
			CH13A11_Read_Gamma(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data); 
		break;
		case 0x07:
			CH13A11_Gamma_OTP_Start(pdev,ep_addr,SigMode ,channel,buffer, LP_B7_Data,HS_B7_Data);//???
		break;
		case 0x0D:           // auto Gamma
			CH13A11_auto_Gamma(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);
		break;
		default:break;
	}		
}
